package cn.com.simple.learning.juc;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @author Jianxing.Jia
 * @date 2022/6/6
 * @description 描述信息
 */
public class FunctionTest {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        Consumer<List<String>> test = FunctionTest::test;
        test.accept(list);
        Function<String, Stream<String>> f = s -> Arrays.stream(s.split(""));
        List<String> collect = list.stream().
                flatMap(f).
                parallel().
                collect(Collectors.toList());
        System.out.println(list);
        System.out.println(collect);

        //
        Function<Integer, Integer> function = x -> x + 1;
        System.out.println(function.apply(1));

        UnaryOperator<Integer> operator = x -> x + 2;
        System.out.println(operator.apply(1));

        IntUnaryOperator intUnaryOperator = x -> x + 3;
        System.out.println(intUnaryOperator.applyAsInt(1));

        IntBinaryOperator intBinaryOperator = (x, y) -> x + y + 4;
        System.out.println(intBinaryOperator.applyAsInt(1, 1));

        // 几连表达式
        Function<Integer, Function<Integer, Integer>> function1 = x -> y -> x + y + 5;
        System.out.println(function1.apply(1).apply(1));

        // 柯里化
        Function<Integer, Function<Integer, Function<Integer, Integer>>> function2 = x -> y -> z -> (x + y + z);
        System.out.println(function2.apply(2).apply(3).apply(4));
    }

    public static void test(List<String> list) {
        list.add("123");
        list = null;
    }
}
